//
//  MM_Cache.m
//  MallManage_IOS
//
//  Created by 张浩 on 2023/9/20.
//

#import "MM_Cache.h"
#import "TMCache.h"

@implementation MM_Cache

ZHSingletonM(MM_Cache)

- (MM_UserModel *)userModel {
    if (_userModel == nil) {
        NSString *userJson = [[TMCache sharedCache] objectForKey:@"userJson"];
        if (userJson && userJson.length > 0) {
            _userModel = [MM_UserModel mj_objectWithKeyValues:userJson];
        }
    }
    return _userModel;
}

//用户token信息
- (void)saveUserJson:(NSString *)userJson {
    
    self.userModel = nil;
    
    [[TMCache sharedCache] setObject:userJson forKey:@"userJson"];
}

//删除用户所有的缓存信息
- (void)removeAllCustomInfo {
    [[TMCache sharedCache] removeAllObjects];
    [MM_Cache removeNSUserDefaultData];
    
    self.userModel = nil;
}

+ (void)removeNSUserDefaultData {
    
    NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
    NSDictionary * dict = [defs dictionaryRepresentation];
    for (id key in dict) {
        [defs removeObjectForKey:key];
    }
    [defs synchronize];
}

@end
